<?php

/*
 * This file is part of the Geek-Zoo Projects.
 *
 * @copyright (c) 2010 Geek-Zoo Projects More info http://www.geek-zoo.com
 * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License
 * @author xuanyan <xuanyan@geek-zoo.com>
 *
 */


require_once ROOT_PATH.'/Abstract/front_abstract.php';

class Action extends front_abstract
{
    function index()
    {
  		$id = _GET('id');
		$page = _GET('page', 0);
  		$param = array(
  			'id' => $id
  		);
		if ($page) {
			$param['page'] = $page;
		}
  		$data = $this->api->comments($this->access_token,  $param);
		$return = $data['comments'];
      
      //字符转换表情
      $t = $this->api->emotions($this->access_token);
      $face = array();
      foreach ($t as $key => $val) {
          $face[$val['phrase']] = '<img src="'.$val['url'].'" />';
      }

      foreach ($return as &$val) {
          $val['text'] = strtr($val['text'], $face);
      }
      // lc del
      // $comments = array_pop($this->api->counts($this->oauth_token, $this->oauth_token_secret,  array($id)));
      $comments = $data['total_number'];
      $this->smarty->assign('comments', $comments);
  		
      $this->smarty->assign('data', $return);
      
      $this->smarty->assign('id', $id);
	  header("Content-type: text/html; charset=utf-8"); 
	  if ($page) {
		  if (!$return) {
		  		die('');
		  }
	      $this->smarty->display('lib/show_reply.html');
	  } else {
	      $this->smarty->display('lib/reply.html');
	  }

    }
    
    function commit(){
        $id = _POST('id');
        $con = _POST('con');
        $msg = $this->api->send_comment($this->$access_token, $id, $con);
		echo $id;
		echo "<br>";
		echo $con;
		echo "<br>";
		print_r($msg);exit;
        if ($msg === false || $msg === null){
        	eixt("Error occured");
        }
        if (isset($msg['error_code']) && isset($msg['error'])){
        	exit("error:" . $msg['error_code']);
        }
        
        if (_POST('item') == 1) {
            $param = array();
            $param['id'] = $id;
            $param['status'] = $con;
            
            $msg = $this->api->repost($this->access_token, $param);
            if ($msg === false || $msg === null){
            	eixt("Error occured");
            }
            if (isset($msg['error_code']) && isset($msg['error'])){
            	exit("error:" . $msg['error_code']);
            }
        }
        
        exit('ok');
    }
}

?>